package Code.StringTraverse;

import java.util.Scanner;

//金额转换
public class Test4 {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入金额:");
        int money = scanner.nextInt();
        if (money > 0 && money <= 9999999) {
            System.out.println(Joint(money));
        } else {
            System.out.println("金额不符合");
        }


    }

    public static String Joint(int number) {
        char[] capital = {'佰', '拾', '万', '仟', '佰', '拾', '元'};

        String str = Transition(number);
        String money = "";
        //判断

        for (int i = 0; i < capital.length; i++) {
            money += str.charAt(i);
            money += capital[i];
        }
        return money;
    }

    public static String Transition(int number) {
        char[] capital = {'零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'};
        //转换
        String money = "";
        while (number > 0) {
            int ge = number % 10;
            number /= 10;
            money = capital[ge] + money;
        }

        //长度为7
        int len = 7 - money.length();
        for (int i = 0; i < len; i++) {
            money = "零"+money;
        }

        return money;
    }
}
